/*
 * conn.h - edbd connection list management functions
 * Clunix, glory@clunix.com, yjlee@clunix.com, 2001.9.7.
 * Clunix, cezanne@clunix.com, 2005.5
 *
 * $Id: edbd_conn.h,v 1.1.1.1.10.2.2.2 2008/03/19 07:11:51 cezanne Exp $
 *
 * Copyright (c) 2001-2005 by Clunix Inc. All Rights Reserved.
 */

#ifndef _EDBD_CONN_H_
#define _EDBD_CONN_H_

#include "libebc.h"

#include "edbd_ecx.h"

typedef struct {
	sr_t		*sr_target;
	ebc_addr_t	addr;
} pathnoti_t;

typedef struct connset {
	ECMBOOL		valid;
	sr_t		*sr_cwd;
	ECMBOOL		system;
	ebc_addr_t	saddr;
	const char	*username;
	ecm_ptrs_t	*conns;
	ecm_hashtable_t	pathnoti;
	ecm_ptrs_t	*atoms;
} connset_t;

typedef struct edbd_conn {
	ecm_uint64	key;
	const char	*username;
	const char	*sessionid;
	ecm_uint32	instant_reaction_level;
	ecm_stack_t	reaction_stack;
	ecm_ebc_t	ebc;
	eds_mod_t	*mod;
	ecx_t		*ecx;
	ecxroot_t	*ecxroot;
	ecm_ptrs_t	*pins, *ghosts;
	connset_t	*connset;
#ifdef TREELOCK_TRACE
	ecm_stack_t	locktrace_stack;
#endif
} conn_t;

extern void conn_prepare_reaction(conn_t *conn);
extern void conn_commit_reaction(conn_t *conn);

extern void conn_insert_pin(conn_t *conn, const sr_t *sr);
extern void conn_insert_ghost(conn_t *conn, const sr_t *sr);

extern void conn_create_ecxroot(conn_t *conn);

extern void edbd_invalidate_cwd(sr_t *);
extern void edbd_unlock_all_cwd(void);
extern void edbd_adjust_all_cwd(void);

extern ECMBOOL edbd_add_pathnoti(conn_t *conn, sr_t *sr_target, ebc_addr_t *paddr);
extern void edbd_del_pathnoti(conn_t *conn, ebc_addr_t *paddr);
extern void edbd_trigger_pathnoti(const sr_t *sr);
extern void edbd_invalidate_pathnoti(sr_t *sr);

typedef void (*atom_cleaner_t)(ecm_ptr_t ptr, ecm_ptr_t ctx);
extern ecm_uint32 conn_reg_atom(conn_t *conn, ecm_ptr_t ptr, atom_cleaner_t cleaner, ecm_ptr_t ctx);
extern ecm_ptr_t conn_get_atom(conn_t *conn, ecm_uint32 key);
extern void conn_put_atom(conn_t *conn, ecm_uint32 key);
extern void conn_unreg_atom(conn_t *conn, ecm_uint32 key);

void edbd_clear_conn(edbd_conn_t edbd_conn);

#endif
